package cn.tedu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cn.tedu.entity.User;
import cn.tedu.utils.DBUtils;

public class UserDao {
	public User finUserByName(String name) {
		//获取连接
		try (Connection conn = DBUtils.getConn();) {
			String sql="select id,username,password from user where username=?";
			PreparedStatement ps=conn.prepareStatement(sql);
			ps.setString(1, name);
			ResultSet rs=ps.executeQuery();
			User user=null;
			while (rs.next()) {
				int id=rs.getInt(1);
				String username=rs.getString(2);
				String password=rs.getString(3);
				user=new User(id, username, password);
			}
			return user;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
